/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#ifndef LIB2D_OBJECTS_IMAGESEQUENCE_H
#define LIB2D_OBJECTS_IMAGESEQUENCE_H

#include <filesystem/String.hpp>
#include <HardwareDependentObject.h>
#include <SharedRep.h>
#include <lib2d/hard/Image.h>
#include <lib2d/hard/Manager.h>
#include <AutoPtr.h>
#include <vector>

namespace liba
{
namespace lib2d
{
namespace objects
{

class ImageSequence :
	public HardwareDependentObject<hard::Manager, std::vector< AutoPtr< hard::Image > > >,
	public SharedPrecachedRepBase
{
public:
	struct Param
	{
		filesystem::String image_name;
		int frame_height;
		Param( const filesystem::String & image_name, int frame_height )
		:	image_name( image_name ),
			frame_height( frame_height )
		{}
		Param()
		{}
		bool operator< ( const Param & p )const	{ return image_name < p.image_name;	}
	};

	void load( const ImageSequence::Param & image_name );

	explicit ImageSequence( const Param & param );
	virtual ~ImageSequence()
	{
		hard::Manager::remove_dependent( this );
	}

	virtual void on_add_hardware(hard::Manager::hardware_type * ha);

	hard::Image * get_image( hard::Renderer * rend, unsigned number )
	{
		std::vector< AutoPtr< hard::Image > > * data = find_data( rend );
		if( data )
		{
			if( number >= data->size() )
				return 0;
			return (*data)[number];
		}
		return 0;
	}
	int get_width()const
	{
		return width;
	}
/*	int get_height()const
	{
		return height;
	}
	*/
private:
	int width;
	int height;
};

} //namespace objects
} //namespace lib2d
} //namespace liba

using namespace liba;

#endif //LIB2D_OBJECTS_IMAGESEQUENCE_H